package com.enjoy.list;

import java.io.BufferedWriter;
import java.io.File;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.nio.file.Files;
import java.nio.file.Paths;

/**
 * 生成14亿个数
 */
public class Generate {
    public static void main(String[] args) throws IOException {

        final String fileName = "f:\\age.txt";
        File file = new File(fileName);

        if (file.exists()) {
            System.out.println("删除文件:" + file.delete());
        }
        System.out.println("创建文件:" + file.createNewFile());

        BufferedWriter objWriter = null;
        objWriter = new BufferedWriter(new OutputStreamWriter(Files.newOutputStream(Paths.get(fileName))));
        long l = System.currentTimeMillis();
        for (int i = 0; i < 1400000000; i++) {
            int age = (int) (Math.random() * 100);
            objWriter.write(age + "\r\n");
        }
        objWriter.flush();
        objWriter.close();
        System.out.println("消耗时间:" + (System.currentTimeMillis() - l) / 1000 + "s");
    }
}
